<?php
	
	header("Content-Type: text/html;charset=utf-8");

	$servername = "localhost";
	$username = "root";
	$password = "456789";
	$dbname = "mysqlstudy";

	$conn = new mysqli($servername,$username,$password,$dbname);
	if($conn -> connect_error){
		die("连接失败:" . $conn -> connect_error);
	}
	mysqli_query($conn, "set names utf8");

	$uid = $_POST["uid"];
	$roles = $_POST["roles"];

	$sdelete = "DELETE FROM use_role WHERE userid='{$uid}'";
	$db = $conn -> query($sdelete);

	for($i=0;$i<count($roles);$i++){
		$sql = "INSERT INTO use_role (ids, userid, roleid) VALUES ('','{$uid}','{$roles[$i]}')";
		$result = $conn -> query($sql);
	}
	
	echo "OK";

?>